<?php
/**
 * The html template file of index method of blog module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
?>
<?php include '../../common/view/header.html.php';?>
<div id="sidebar">
<div class="accordion open">
<a href=""  class="accordion-toggle">升级操作<i class="slider_arrow"></i></a>
<div class="accordion-body">
<ul>
<li class="active"><?php echo html::a($this->createLink($moduleName,'updateopt'), '升级列表');?></li>
<li><?php echo html::a($this->createLink($moduleName,'basicconf'), '基础服务配置');?></li>

</ul>
</div>
</div>
</div>
 <div id="main" class="alarm_mynews">
    <div class="main_title">升级操作<span class="level_divide">&gt; &gt;</span>升级列表</div>
    <div class="main_body">
    	<div id="report_title">
              <div class="right">
                    <span id="search_lab">关键字：</span>
                    <div id="item_search" style="float:left">
                        <input type="text" name="key_word" id="key_word" class="" value="<?php if(isset($_GET['key_word'])) echo $_GET['key_word']; ?>" style="width:120px;" placeholder="请输入关键词"/>
                        <span class="status_lab">状态:</span>
                        <div class="dropdown">
                          <select name="status" id="status">
                            <option value="all" <?php if(isset($_GET['status'])&&$_GET['status']=="all"){echo 'selected="selected"';}?>>全部</option> 
                            <option value="1" <?php if(isset($_GET['status'])&&$_GET['status']=='1'){echo 'selected="selected"';}?>>启用</option> 
                            <option value="0" <?php if(isset($_GET['status'])&&$_GET['status']=='0'){echo 'selected="selected"';}?>>禁用</option> 
                        </select>
                        </div>
                        <a href="javascript:void(0);" class="search" onClick="startSearch('updateopt','updateopt','key_word','status')" title="查找"></a>
                    </div> 
            	</div>  
        	</div>
        <table class="table">
            <thead>
                <tr>
                    <td width="50px">ID</td>
                    <td>网站名称</td>
                    <td>IPv6前缀</td>
                    <td>主域名</td>
                    <td width="60">状态</td>
                    <td width="120px;" align="center">操作</td>
                </tr>
            </thead>
            <tbody>
             <?php foreach($sites_info_list as $item):?>
              <tr>
                <td><?php echo $item->sites_id;?></td>
                <td><?php echo $item->sites_name;?></td>
                <td><?php echo $item->pre_v6;?></td>
                <td><?php echo $item->main_domain;?></td>
                <td
                  <?php 
                     if($item->status==1){
                          echo 'style="background:#0F0"';
                     }else{
                          echo 'style="background:#F00"';
                     }
                   ?>>
                	<?php 
                     if($item->status==1){
                          echo '启用';
                     }else{
                          echo '禁用';
                     }
                   ?>
                </td>
                <td align="center">
                    <a href="javascript:void(0)" onClick="add_sites(<?php echo $item->sites_id;?>)">编辑</a>
                      &nbsp;&nbsp;
				    <a href="javascript:void(0)" onClick="del_sites(<?php echo $item->sites_id;?>)">删除</a>
                </td>
              </tr>  
              <?php endforeach;?>  
            </tbody>
        </table>
            <div>
               <div class="control-group" style="margin-top:10px; float:left">
                <label class="control-label" for=""></label>
                    <div class="controls">
                        <input type="button" class="btn btn-primary" value="添加站点" onClick="add_sites()" />
                        
                        <input type="button" class="btn btn-primary" value="写入配置" onClick="set_sites()" />
                        
                        <input type="button" class="btn btn-primary" value="站点访问检测" onClick="check_sites()" />
                    </div>
               </div>
               
                 <div class="pages">
                <?php 
                   // echo html::a(inlink('create'), $lang->blog->add, '', "class='btn btn-primary'");
                    $pager->show('right', 'full');
               ?>
                </div>
            </div>
         </div>
    </div>
<?php include '../../common/view/footer.html.php';?>
<script src="<?php echo $jsRoot?>iDialog/jquery.iDialog.js" dialog-theme="default"></script>
<script type="text/javascript">
	//写入站点
   function check_sites(){
	  $.dialog({
		width:300,
		lock:true,
		title:'提示信息',
		content:'确定要对所有站点状态进行检测吗？',
		btn: {                      
		  ok: {                     
			val: '确定',            
			type: 'green',  
			click: function(btn) {
				var wait_dialog=wait_info('正在检测,请稍候');
				$.post("index.php?m=updateopt&f=test_sites",
					function(data){
						wait_dialog.hide();
						if(data=='success'){
						   tipInfo('检测成功');
						}else{
						   tipInfo('检测超时');
						}
					});
			}
		  },
		  cancle: {         
			val: '取消'
		  }
		}
	  });
   }
		//写入站点
	   function set_sites(){
	      $.dialog({
			width:300,
			lock:true,
			title:'提示信息',
			content:'确定把站点信息写入配置中？',
			btn: {                      
			  ok: {                     
				val: '确定',            
				type: 'green',  
				click: function(btn) {
					var wait_dialog=wait_info('正在操作,请稍候');
				    $.post("index.php?m=updateopt&f=write_sites",
						function(data){
							wait_dialog.hide();
							if(data=='success'){
							   tipInfo('写入成功');
							}else{
							   tipInfo('写入失败');
							}
						});
				}
			  },
			  cancle: {         
				val: '取消'
			  }
			}
		  });
	   }
		//删除
	   function del_sites(sites_id){
	      $.dialog({
			width:300,
			lock:true,
			title:'提示信息',
			content:'确定要删除该站点吗？',
			btn: {                      
			  ok: {                     
				val: '确定',            
				type: 'green',  
				click: function(btn) {
				    $.post("index.php?m=updateopt&f=del_sites_info",{sites_id:sites_id},
						function(data){
							if(data=='success'){
							   tipInfo('删除成功');
							   location.reload();
							}else{
							   tipInfo('删除失败');
							}
						});
				}
			  },
			  cancle: {         
				val: '取消'
			  }
			}
		  });
	   }
	  
      /**
		添加编辑
		*/
		function add_sites(sites_id){
			$.dialog({
				lock:true,
				width:700,
				title:'添加站点',
				btn: {                      //可以任意定义按钮个数
				  ok: {                     //按钮的key值，下次可用个btn方法从新设置
					val: '确定',            //按钮显示的文本
					id:'submitbt',
					type: 'green',         //样式可选参数green, blue, red, yellow .默认白色。
					click: function(btn) {
					  if($('#add_sites_form').checkAjaxForm(1)){
						  $.post("index.php?m=updateopt&f=done_add_sites",$("#add_sites_form").serialize(),
							function(data){
								var opt="添加";
								if(sites_id){
				   					opt="编辑";
								}
								if(data=='success'){
									tipInfo(opt+'成功');
									location.reload();
								}else{
								   tipInfo(opt+'失败');
								}
							});
					   }else{
					   		return false;
					   }
					}
				  },
				  cancle: {
					val: '取消'
				  }
				},
			 init:function(){
			    var that=this;
				 if(sites_id){
				    that.$title.html('编辑站点');
				 }
				 $.post("index.php?m=updateopt&f=add_sites",{sites_id:sites_id},
					function(data){
					    that.$content.html(data);
						that.$dialog.css('height','auto');
						/*that.$content.css('height','200');
						that.$content.css('overflow','auto');*/
						$('#add_sites_form').checkForm(1,'submitbt');
				    });
			  }
			 });
	   }
</script>
